/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bgu.ppm.dat.view;

import javax.swing.DropMode;
import javax.swing.TransferHandler;
import javax.swing.border.EmptyBorder;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;

/**
 *
 * @author user
 */
public class CheckBoxTextEditingTreeView extends javax.swing.JPanel {

    /**
     * Creates new form CheckBoxTextEditingTreeView
     */
    public CheckBoxTextEditingTreeView() {
        initComponents();

        tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode(new SelecteableItem<>("Empty", false))));

        tree.setCellEditor(new TreeCheckBoxRenderer());
        tree.setCellRenderer(new TreeCheckBoxRenderer());  
        
        jScrollPane1.setBorder(new EmptyBorder(0, 0, 0, 0));
    }

    public void setModel(TreeModel model) {
        tree.setModel(model);
    }
    
    public boolean getDragEnabled() {
        return tree.getDragEnabled();
    }
    
    public void setDragEnabled(boolean b) {
        tree.setDragEnabled(b);
    }
    
    public DropMode getDropMode() {
        return tree.getDropMode();
    }
    
    public void setDropMode(DropMode m) {
        tree.setDropMode(m);
    }
    
    @Override
    public void setTransferHandler(TransferHandler handler) {
        tree.setTransferHandler(handler);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tree = new javax.swing.JTree();

        setLayout(new java.awt.BorderLayout());

        jScrollPane1.setBorder(null);

        tree.setAutoscrolls(true);
        tree.setEditable(true);
        tree.setRootVisible(false);
        tree.setShowsRootHandles(true);
        tree.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                treeKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(tree);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void treeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_treeKeyPressed
//        switch (evt.getKeyCode()) {
//            case KeyEvent.VK_SPACE:
//                if (tree.getSelectionPath() != null) {
//                    DefaultMutableTreeNode item = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
//                    ((SelecteableItem) item.getUserObject()).flipSelected();
//                    tree.getModel().valueForPathChanged(tree.getSelectionPath(), item.getUserObject());
////                    tree.startEditingAtPath(tree.getSelectionPath());
//                }
//
//                break;
//
//            case KeyEvent.VK_ENTER:
//                if (tree.getSelectionPath() != null) {
//                    tree.startEditingAtPath(tree.getSelectionPath());
//                }
//                break;
//        }
    }//GEN-LAST:event_treeKeyPressed


    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTree tree;
    // End of variables declaration//GEN-END:variables
}
